public class demo3 {
    static int tDistance=0;
    static int rDistance=0;
    public static void main(String[] args) {
        Thread Tortiost =new Thread(()->{
            for (int i = 1; i <= 800; i++) {
                if (rDistance==800){
                    System.out.println("兔子赢得了比赛，此时乌龟才跑了"+tDistance+"米");
                    break;
                }else {
                    tDistance+=1;
                    if (tDistance%100==0) {
                        if (rDistance == 700) {
                            System.out.println("乌龟跑了" + tDistance + "米，此时兔子在睡大觉");
                        }else {
                            System.out.println("乌龟跑了"+tDistance+"米，此时兔子跑了"+rDistance+"米");
                        }
                        try {
                            Thread.sleep(1500);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });
        Thread Rabbit=new Thread(()->{
            for (int i = 1; i <= 800/5; i++) {
                if (tDistance==800){
                    System.out.println("乌龟赢得了比赛，此时兔子跑了"+rDistance+"米");
                    break;
                }else {
                    rDistance+=5;
                    if (rDistance%100==0){
                        System.out.println("兔子跑了"+rDistance+"米，乌龟跑了"+tDistance+"米");
                        if (rDistance==700){
                            System.out.println("兔子睡大觉10000ms");
                            try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e) {
                                throw new RuntimeException(e);
                            }
                        }
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        });
        Rabbit.start();
        Tortiost.start();
    }
}
